/**
 * @param _container 对应div标签的id字符串，如"#container"
 * @param _dates X轴显示的时间数组
 * @param _titleName 
 * @param _serises serises值
 */
function getColumn(_container,_dates,_titleName,subtitle,_series,clickFunc) {
	var container = _container;
	var dates = _dates;
	var titleName = _titleName;
	var series = _series;//serises中需要的数据数组 
    $(container).highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: titleName//根据用户权限及所有部门设定
        },
        subtitle: {
            text: subtitle
        },
        xAxis: {
            categories: dates,//日期由系统获取
            labels: {
                rotation: 0 //倾斜角度
            }
        },
        yAxis: {
            min: 0,
            title: {
                text: '元（￥）'
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                '<td style="padding:0"><b>{point.y:.2f} 元</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0,
                pointWidth:20,
                events:{
                	click:clickFunc
                }
            }
        },
        series: series,
        credits: {
            enabled: false
       }
    });
}
function getColumn2(parameters) {
	var container = parameters.container;//容器
	var dates = parameters.dates;//series数据
	var titleName = parameters.titleName;//标题
	var subtitle = parameters.subtitle;//副标题
	var clickFunc = parameters.clickFunc;//点击事件
	var series = parameters.series;//series中需要的数据数组 
	var pointWidth = parameters.pointWidth;//柱体宽度
	var rotation = parameters.rotation; //柱体倾斜角度
	var yAxisTitle = parameters.yAxisTitle; //Y轴单位
	var xCount = dates.length;//X轴数目
	var digitNum = parameters.digitNum;//保留小数点位数
	var hasApostrophe = parameters.hasApostrophe;//当X轴数量太多时，是将X轴值以省略号表示
	var type = parameters.type;//柱状图类型，默认为colum
	var legendEnable = parameters.legendEnable;
	if(typeof legendEnable == "undefined" || legendEnable == null){
		legendEnable = true;
	}
	if(typeof type == "undefined" || type == null){
		type = 'column';
	}
	if(typeof hasApostrophe==!"boolean"){
		hasApostrophe = true;
	}
	if(typeof pointWidth=="undefined"||pointWidth==null||pointWidth==""){
		pointWidth = 20;//柱体宽度
		if(xCount>5&&xCount<12){
			pointWidth = 100 / xCount;//柱体宽度
		} else if(xCount >= 12){
			pointWidth = 8;
		}
	}
	if(typeof yAxisTitle=="undefined"||yAxisTitle==null||yAxisTitle==""){
		yAxisTitle = '元(￥)';
	}
	if(typeof digitNum=="undefined"||digitNum==null||digitNum==""){
		digitNum = 2;
	}
	/*if(rotation==undefined||rotation==null||rotation==""){
		rotation = 0;//倾斜角度
		var count = dates.length;//X轴数目
		if(count>5&&count<=10){
			rotation = -45;//倾斜角度
		} else if(count>10){
			rotation = 90;//倾斜角度
		} else {
			
		}
	}*/
	$(container).highcharts({
		chart: {
			type: type,
			backgroundColor : '#F0F0F0'
		},
		title: {
			align: "left",//程度标的目标地位
			text: titleName//根据用户权限及所有部门设定
		},
		subtitle: {
			text: subtitle
		},
		xAxis: {
			categories: dates,
			labels: {
			   // enabled: false, 
				//format: "...",
				//formatter:formatXData(xCount),
				formatter:function (){//根据X轴数目的多少，截取X值长度以节省X轴空间
					var xValue = this.value;
					if(hasApostrophe){
						if(xCount>4&&xCount<=6&&xValue.length>8){
							return xValue.substring(0,8)+"...";
						} else if(xCount>6&&xCount<=10&&xValue.length>6){
							return xValue.substring(0,6)+"...";
						} else if(xCount>10&&xCount<=15&&xValue.length>4){
							return xValue.substring(0,4)+"...";
						} else if(xCount>15&&xCount<=20&&xValue.length>3){
							return xValue.substring(0,3)+"...";
						} else if(xCount>20&&xValue.length>2){
							return xValue.substring(0,2)+"...";
						} else {
							return xValue;
						}
					}else{
						return xValue;
					}	
				},
				rotation: rotation
			}
		},
		yAxis: {
			min: 0,
			title: {
				text: yAxisTitle
			}
		},
		legend: {
			enabled: legendEnable
		},
		tooltip: {
			headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
			pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
			'<td style="padding:0"><b>{point.y:.'+digitNum+'f} '+yAxisTitle+'</b></td></tr>',
			footerFormat: '</table>',
			shared: true,
			useHTML: true
		},
		plotOptions: {
			column: {
				// x轴每个点只用一个柱，则这个属性设置的是相邻的两个点的柱之间的间距。
		        // 如果x轴每个点有2个柱，则这个属性设置的是左侧点的右柱与右侧点的左柱之间的间距。
		        // 0.2的含义是，如果x轴长100px,则间距是100*0.2=20px
				pointPadding: 0.2,
				borderWidth: 0,
				pointWidth:pointWidth,
				// 如果x轴一个点有两个柱，则这个属性设置的是这两个柱的间距。
				events:{
					click:clickFunc
					//afterAnimate:afterAnimate
				}
			}/*,
			series: {
	            groupPadding: 0.1
	           // animation: false
	        }*/
		},
		series: series,
		credits: {
			enabled: false
		}
	});
}

/**
 * @param _container 应div标签的id字符串，如"#container"
 * @param _titleName
 * @param _dataMap  serises 对应的二维数组
 */
function getPie(_container,_titleName,_dataMap,clickFunc) {
	var container = _container;
	var titleName = _titleName;
	var dataMap = _dataMap;//serises中需要的数据Map
    return $(container).highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: titleName//根据用户权限及所有部门设定
        },
        tooltip: {	
    	    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: false,
                    color: '#000000',
                    connectorColor: '#000000',
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                },
                showInLegend: true,
                events:{
                	click:clickFunc
                }
            }
        },
        series: [{
            type: 'pie',
            name: '所占比例',
            data:dataMap
        }],
        credits: {
            enabled: false
       }
    });
}
function getPie2(_container,_titleName,_dataMap,_colors,clickFunc) {
	var container = _container;
	var titleName = _titleName;
	var dataMap = _dataMap;//serises中需要的数据Map
	var colors = ['#bed2b6','#c35655','#17507d','#da9558','#3d6e53',
	              '#E0FFFF','#DA70D6','##9370DB','#6B8E23','#FFD700',
	              '#7cb5ec','#434348','#90ed7d','#f7a35c','#8085e9',
		          '#f15c80','#e4d354','#8085e8','#8d4653','#91e8e1',
		          '#434348','#90ed7d','#f7a35c','#8085e9','#f15c80',
		          '#e4d354','#8085e8','#8d4653','#91e8e1','#7cb5ec'];//颜色,默认30种，暂能满足需求
	if(_colors != null){
		colors = _colors;//颜色
	}else{
	}
	return $(container).highcharts({
		chart: {
			plotBackgroundColor: null,
			plotBorderWidth: null,
			plotShadow: false
		},
		title: {
			text: titleName//根据用户权限及所有部门设定
		},
		tooltip: {	
			pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
		},
		plotOptions: {
			pie: {
				allowPointSelect: true,
				cursor: 'pointer',
				dataLabels: {
					enabled: false,
					color: '#000000',
					connectorColor: '#000000',
					format: '<b>{point.name}</b>: {point.percentage:.1f} %'
				},
				showInLegend: true,
				events:{
					click:clickFunc
				}
			}
		},
		colors:colors,//颜色数组
		series: [{
			type: 'pie',
			name: '所占比例',
			data:dataMap
		}],
		credits: {
			enabled: false
		}
	});
}
function getPie3(parameters) {
	var container = parameters.container;//容器
	var titleName = parameters.titleName;//标题
	var dataMap = parameters.dataMap;//serises中需要的数据Map
	var colors = parameters.colors;//serises颜色
	var clickFunc = parameters.clickFunc;//点击事件
	var yAxisTitle = parameters.yAxisTitle; //数值的单位
	var digitNum = parameters.digitNum; //数值保留位数
	
	if(typeof digitNum=="undefined"||digitNum==null||digitNum==""){
		digitNum = 2;
	}
	if(!colors){
		/*var colors = ['#DA70D6','#9370DB','#6B8E23','#FFD700','#bed2b6',
		              '#c35655','#17507d','#da9558','#E0FFFF','#3d6e53',
		              '#7cb5ec','#434348','#90ed7d','#f7a35c','#8085e9',
			          '#f15c80','#e4d354','#8085e8','#8d4653','#91e8e1',
			          '#434348','#90ed7d','#f7a35c','#8085e9','#f15c80',
			          '#e4d354','#8085e8','#8d4653','#91e8e1','#7cb5ec'];*/
		var colors = [  '#ff7f50', '#87cefa', '#da70d6', '#32cd32', '#6495ed', 
					    '#ff69b4', '#ba55d3', '#cd5c5c', '#ffa500', '#40e0d0', 
					    '#1e90ff', '#ff6347', '#7b68ee', '#00fa9a', '#ffd700', 
					    '#6b8e23', '#ff00ff', '#3cb371', '#b8860b', '#30e0e0' 
		]//颜色,默认20种，暂能满足需求
	}
	
	return $(container).highcharts({
		chart: {
			plotBackgroundColor: null,
			plotBorderWidth: null,
			plotShadow: false,
			animation: false,
			backgroundColor:'#F0F0F0',
			marginRight: 120
		},
		legend: {
			layout: 'vertical',
			align: "right",//程度标的目标地位
			verticalAlign: "bottom",//垂直标的目标地位
			x: 0,//间隔x轴的间隔
			y: 0//间隔Y轴的间隔
		},
		title: {
			align: "left",//程度标的目标地位
			text: titleName//根据用户权限及所有部门设定
		},
		tooltip: {	
			pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b><br />具体数值: <b>{point.y:.'
				+digitNum+'f}'+yAxisTitle
		},
		plotOptions: {
			pie: {
				allowPointSelect: true,
				cursor: 'pointer',
				dataLabels: {
					enabled: false,
					color: '#000000',
					connectorColor: '#000000',
					format: '<b>{point.name}</b>: {point.percentage:.1f} %'
				},
				showInLegend: true,
				events:{
					click:clickFunc
				}
			}/*,
			series: {
				animation: false
			}*/
		},
		colors:colors,//颜色数组
		series: [{
			type: 'pie',
			name: '所占比例',
			data:dataMap
		}],
		credits: {
			enabled: false
		}
	});
}

/**
 * 生成走势图，由于暂时不需要，以下功能并未完成
 * @param _container div标签的id字符串，如"#container"
 * @param _dates
 * @param _titleName
 * @param _subtitle
 * @param _series
 */
function getPolyline(_container,_dates,_titleName,_subtitle) {
	var container = _container;
	var dates = _dates;
	var titleName = _titleName;
	var subtitle = _subtitle;
	//var series = _series;//serises中需要的数据数组 
	
    $(container).highcharts({
        chart: {
            type: 'line'
        },
        title: {
            text: titleName
        },
        subtitle: {
            text: subtitle
        },
        xAxis: {
            categories: dates
        },
        yAxis: {
            title: {
                text: '价格 (元)'
            }
        },
        tooltip: {
            enabled: false,
            formatter: function() {
                return '<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'元';
            }
        },
        plotOptions: {
            line: {
                dataLabels: {
                    enabled: true
                },
                enableMouseTracking: false
            }
        },
        series: [{
            name: 'Tokyo',
            data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
        }, {
            name: 'London',
            data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
        },{
            name: 'Lonfffdon',
            data: [1.9, 2.2, 3.7, 84.5, 5.9, 5.2, 7.0, 6.6, 4.2, 13.3, 9.6, 6.8]
        }]
    });
}